home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / progem.lzh / wind15.prf < prev    next >
Encoding:
Text File  |  1987-06-23  |  13.9 KB  |  282 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!
  18. .!****************************************************************************
  19. .!
  20. .!            Begin Part XV
  21. .!
  22. .!****************************************************************************
  23. .!
  24. .PART XV Coping with GEMDOS
  25. .PP
  26. While it's fun playing with windows and object trees,  one of
  27. the  day-to-day realities of working with the ST is its  operating
  28. system, GEMDOS.  A successful application should insulate the user
  29. from  the foibles and occasional calamities of the machine's  file
  30. system.  The GEM environment provides some minimal tools for doing
  31. this,  but a good deal of responsibility still rests with you, the
  32. programmer.
  33. .PP
  34. This column (#15 in the ST PRO GEM series) tries to  address
  35. the  GEM/DOS integration problem by providing you some stock  code
  36. for common functions, along with a discussion of some of the worst
  37. "gotchas" lurking for the unwary.  The download for this column is
  38. GMCL15.C, and it can be found in DL3 of PCS-58.  You should obtain
  39. and list this file before proceeding.
  40. .SH A BIT OF HISTORY.
  41. There has been a good deal of  confusion
  42. in  the Atari press and among developers over what GEMDOS is,  and
  43. how it relates to TOS and CP/M-68K.   It's important to clear this
  44. up,  so  you can get a true picture of what GEMDOS is intended  to
  45. do.  The best way is to tell the story of GEMDOS' origins, which I
  46. can do, because I was there.
  47. .PP
  48. As  most developers are aware,  GEM was first implemented  on
  49. the  IBM  PC.   PC GEM performed two functions.   The first was  a
  50. windowed graphics extension to the PC environment.  The second was
  51. a  visual  shell,  the Desktop,  which ran on top of the  existing
  52. operating system, PC-DOS.
  53. .PP
  54. When work started on moving GEM to the ST, there were two big
  55. problems.   First,  no STs actually existed.  Second, there was no
  56. operating system on the 68000 with which GEM and the Desktop could
  57. run.   Unix  was  too  large,  and  CP/M-68K lacked  a  number  of
  58. capabilities,  such  as  hierarchical files,  which were needed to
  59. support GEM.
  60. .PP
  61. Work on porting the graphics parts of GEM to the 68000 had to
  62. start immediately to meet schedules.   Therefore, CP/M-68K running
  63. on  Apple Lisa's was used to get this part of the project off  the
  64. ground.   Naturally,  the  Alcyon C compiler and other tools which
  65. were native to this environment were used.
  66. .PP
  67. In  parallel,  an  effort was begun to write a new  operating
  68. system for the 68000,  which would ultimately become the ST's file
  69. system.   It was designed to be a close clone of PC-DOS,  since it
  70. would   perform   the   same  functions  for  GEM   in   the   new
  71. environment.  At  this  point,  the term TOS was introduced.   TOS
  72. really meant "the operating system,  whatever it may be, that will
  73. run on the ST",  since not even the specifications,  let alone the
  74. code, were complete at that time.
  75. .PP
  76. The  first engineer to work on "TOS" at Digital Research  was
  77. Jason  Loveman.   This  name  leaked  to the press,  and  in  some
  78. distorted  fashion generated a rumor about "Jason DOS",  which was
  79. still  just  the same unfinished project.   As "TOS"  became  more
  80. solid,  the  developer's tools were ported to the new  environment
  81. one by one, and the GEM programming moved with them.  CP/M-68K was
  82. completely  abandoned,  though the old manuals for C and the tools
  83. lived on and are still found in the Atari developer's kit.
  84. .PP
  85. All of this work had been done on Lisas or Compupro  systems
  86. fitted with 68000 boards.   At this point,  workable ST prototypes
  87. became  available.   An  implementation  of "TOS" for  the  target
  88. machine  was  begun,  even before the basic operating  system  was
  89. fully completed.
  90. .PP
  91. The  other  intent for the new operating system was to  be  a
  92. base for GEM on other 68000 systems as well as the ST.  Because of
  93. this,  Digital  Research  named  it  GEMDOS when  it  was  finally
  94. complete,  thus providing the final bit of nomenclature.  "TOS" as
  95. now  found  in the ST is in fact a  particular  implementation  of
  96. generic GEMDOS, including the ST specific BIOS.
  97. .PP
  98. So,  GEMDOS is a PC-DOS clone,  but,  not quite.  There are
  99. enough  differences  to  cause  problems  if  they  are   ignored.
  100. (Remember,  it looks like a duck, and quacks like a duck, but it's
  101. not a duck.)
  102. .SH GOING FOR IT.
  103. As a first example,  consider the  routines
  104. open_file()  and create_file() at the beginning of  the  download.
  105. They make use of the GEMDOS calls Fopen() and Fcreate().  You will
  106. notice that these names are not the ones specified in the  Digital
  107. Research  GEMDOS  manual.   Developers who have used PC  GEM  will
  108. also  observe that they are radically different from the  function
  109. names in the PC-DOS bindings.
  110. .PP
  111. In  fact,  all  of  the GEMDOS function calls on the  ST  are
  112. defined  as  macros  in the file osbind.h,  distributed  with  the
  113. developer's  kit.   At compile time they are turned into calls  to
  114. the  assembly  language  routine gemdos(),  part of  the  osbind.o
  115. binary.  So, if you find the naming conventions to be particularly
  116. offensive  for  some reason,  just edit the appropriate macros  in
  117. osbind.h.
  118. .PP
  119. In  DRI's PC-DOS bindings,  any error codes were returned  in
  120. the  global  variable  DOS_ERR.    In  the  GEMDOS  bindings,  the
  121. operation result or an error code is returned as the value of  the
  122. calling  function.   In  the  case of Fopen() and  Fcreate(),  the
  123. result  is  a  valid file handle if it is  positive.   A  negative
  124. result  is  always an error code,  indicating that  the  operation
  125. failed.
  126. .PP
  127. An application which encounters a GEMDOS error should display
  128. an  alert,  and  query  for  retry or abort.   The  type  of  loop
  129. structure  exemplified  by open_file()  and  create_file()  should
  130. be  usable with most GEMDOS functions which might fail.   The  AES
  131. provides  a  function,  form_error,  which  implements  a  set  of
  132. "canned" error alerts appropriate to the various possible errors.
  133. .PP
  134. However,  this is where the fun starts.  For unknown reasons,
  135. the form_error on the ST expects to see PC-DOS,  not GEMDOS, error
  136. codes as it's input!  Therefore you need a routine to translate one
  137. into the other.   The routine dos_error() in the download provides
  138. this  function.   The  GEMDOS errors are in the same  sequence  as
  139. those  for  PC-DOS,  but  their numerical order  is  reversed  and
  140. shifted.   Notice  also  that  dos_error() does  NOT  perform  the
  141. translation if the error code is less than -50.   These codes have
  142. no  PC-DOS  equivalent;  computing a bogus translation will  cause
  143. form_error to crash.   Instead,  they are passed through verbatim,
  144. resulting in a "generic" alert which gives only the error number.
  145. .PP
  146. The  other major task in integrating a GEM  application  with
  147. the  file  system is selecting file names for  input  and  output.
  148. Again,  the AES provides some assistance with the fsel_input call,
  149. which invokes the standard file selector dialog.
  150. .PP
  151. There  are several drawbacks to the standard  file  selector.
  152. One  is that the "ITEM SELECTOR" title is constant and  cannot  be
  153. changed  by the application.   This could cause confusion  for
  154. the  user,  since it may not be clear which of several  functions,
  155. closely spaced in the FILE menu,  was actually invoked.   While it
  156. might  be  possible  to find and "rewire" the  AES  resource  that
  157. defines  the file selector,  it is unlikely that such an  approach
  158. would be portable to a later version of ST GEM.
  159. .PP
  160. A  viable approach to eliminating confusion is to  display  a
  161. small "marquee" box, with a message defining the operation, on the
  162. screen  just  above  the  file selector.  To  do  this,  you  must
  163. initialize  the location of the box so that it is outside  of  the
  164. file selector's bounds,  and then draw it just before invoking the
  165. file  selector.   This  way  they will  appear  together.   Before
  166. returning  to its main event loop,  the application should post  a
  167. redraw  message for the "marquee" area.   The AES will merge  this
  168. redraw  with the one generated by fsel_input,  and the result will
  169. be received by the application's evnt_multi.
  170. .PP
  171. Another problem with the file selector is that it resets your
  172. application's virtual workstation clip rectangle without  warning.
  173. There  are other AES functions,  such as objc_draw,  which also do
  174. this,  but  the file selector can be troublesome because it may be
  175. the only AES call used by some VDI-based ST applications.
  176. .PP
  177. The veteran developer will also notice that the file selector
  178. takes  and returns the path and filename as two separate  strings,
  179. while the GEMDOS file functions require a fully pathed file  name.
  180. Also, the file selector doesn't remember its "home" directory; you
  181. are responsible for determining the default directory, and keeping
  182. track of any changes.  The remainder of the download and column is
  183. devoted  to  set of utilities which should alleviate some  of  the
  184. "grunt work" of these chores.
  185. .PP
  186. The  top level routine in this collection is get_file().   It
  187. is  called with two string arguments.   The first must point to  a
  188. four  byte string area containing the desired file name  extension
  189. (three  characters plus a null).   The second is the default  file
  190. name.
  191. .PP
  192. If the default file name is non-null, then get_file() invokes
  193. parse_fname() to break it into path and name.   Parse_fname() also
  194. adds  the  necessary "wild card" file specification to  the  path,
  195. using the extent name given as input.
  196. .PP
  197. If  no  default  file was supplied,  or the default  did  not
  198. contain  a  path,  the routine get_path() is invoked to  find  the
  199. current  default directory and construct a legal path  string  for
  200. it.
  201. .PP
  202. The   results   of  these  manipulations  are   supplied   to
  203. fsel_input.   Notice  that  the  result of the  file  selector  is
  204. returned via its third argument,  rather than as a function value.
  205. If  the result is TRUE,  get_file() merges the temporary path  and
  206. file  string,  storing the result via the second input  parameter.
  207. This  result  string is suitable for use with Fopen,  and  may  be
  208. resubmitted  to get_file() when the next operation is  invoked  by
  209. the user.
  210. .PP
  211. Parse_fname() is straight-forward C.  It looks backward along
  212. the  file to find the first character which is part of  the  path.
  213. The tail of the filename is copied off, and its former location is
  214. overlaid with the wild card specification.
  215.  
  216.      Get_path()  is a bit more interesting.   It makes use of  two
  217. GEMDOS  functions,  Dgetdrv() and Dgetpath() to obtain the default
  218. disk drive and directory, respectively.  Note that Dgetpath() will
  219. return  a null string if the current default is the root,  but  it
  220. puts  a back-slash at the beginning of the path  otherwise.   This
  221. forces  a  check for insertion in the root case,  since  the  file
  222. selector  wants  to  see something like  "A:\*.RSC",  rather  than
  223. "A:*.RSC".   After  making  this fix,  get_path() concatenates the
  224. wild card specification derived from the input extent.
  225. .PP
  226. The last routine in the download is new_ext().   This utility
  227. is  useful if your application uses more than one associated  file
  228. at a time.   For instance, the Resource Construction Set uses both
  229. an RSC and a DEF file, with the same base name.  New_ext() takes a
  230. fully  formed file name,  and replaces its old extent with the new
  231. one  which you supply.   This lets you quickly generate both  file
  232. names after one call to the file selector.   Notice that new_ext()
  233. looks BACKWARD along the name to find the delimiting period, since
  234. this  character  can also be part of a subdirectory  name  in  the
  235. path.
  236. .PP
  237. So  we reach the end of the code and this column.   Hopefully
  238. both will keep you profitably occupied for a while.  July's column
  239. will return to graphics topics,  with a look at writing customized
  240. rubber  box and drag box routines,  and ways to implement your own
  241. "pop-up"  menus.   August  will  bring techniques  for  displaying
  242. progress  indicators,  associating  dialog and menu  entries  with
  243. keystrokes, and customizing objc_edit.
  244. .SH I CAN'T HEAR YOU!
  245. The Feedback mailbag has been  noticably
  246. flat  of  late.   There have been a number of compliments  on  the
  247. column,  which  are  much  appreciated,  and some suggestions  for
  248. topics  which fall outside the bounds of this series.   The latter
  249. have  been passed on to Antic for possible inclusion in their  new
  250. ST quarterly, START.
  251. .PP
  252. One recurring problem is finding the downloads.   A number of
  253. the  earlier columns say they are in PCS-132 (the old  SIG*ATARI),
  254. and  one says PCS-57 (mea culpa).   In fact,  ALL of the downloads
  255. are  now  in DL3 of PCS-58 (ATARI16).   Filenames for  first  nine
  256. columns  are  all in the form GEMCLx.C,  where x is  the  column's
  257. digit.   For reasons unknown to me,  the next two files were named
  258. GEMC10.C  and  GEMC11.C;  the  latest  two  downloads  are  called
  259. GMCL13.C and GMCL15.C.   The latter naming pattern should continue
  260. into the future.
  261. .PP
  262. Undoubtedly,  one reason for the shortage of questions is the
  263. amazing ability to get a quick answer on the Developer's SIG, PCS-
  264. 57.   This  is  a  good  sign  of  a  strong  Atari  community  on
  265. Compuserve.   However,  the  SIG message style doesn't really lend
  266. itself  to lengthy explanation,  so suggestions for longer  topics
  267. are always welcome here.
  268. .PP
  269. Finally,  I  am now beginning the process of collecting these
  270. columns and some additional material into a book.  In doing so, it
  271. would  be  helpful to know if you feel that any part of  GEM  has
  272. been  slighted  in my discussions.   If so,  let  me  know.   Your
  273. suggestions will appear in future columns and finally make their
  274. way into the book.
  275. .!
  276. .!
  277. .!*****************************************************************************
  278. .!*                                          *
  279. .!*                End Part 15                      *
  280. .!*                                          *
  281. .!*****************************************************************************
  282.